﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Reflection;
using DMS.Business.Modules.Organization;
using DMS.Business.Modules.SystemManage;
using DMS.Business.Utility;

namespace GMS.Web.Common.Services
{

    public partial class RoleService : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string methodName = Request.Params["method"];
            MethodInfo method = this.GetType().GetMethod(methodName);

            method.Invoke(this, null);
        }

        public void Save()
        {
            string userString = Request.Params["userString"];
            string roleId = Request.Params["roleId"];
            if (!String.IsNullOrEmpty(userString))
            {
                string[] infos = userString.Split('~');
                string[] userInfo = null;
                string userId, name, scope;
                foreach (string s in infos)
                {
                    if(String.IsNullOrEmpty(s))
                        continue;
                    userInfo = s.Split(',');
                    userId = userInfo[0];
                    name = userInfo[1];
                    scope = userInfo[2];
                    UserHelper.SetActorRole(userId, roleId, scope);
                }
            }
            
            Response.Clear();
            Response.ContentType = "application/json";
            Response.Charset = "UTF-8";
            Response.End();
        }
    }
}